package com.djl.rabbitmq.two;

import com.djl.rabbitmq.utils.RabbitMqUtils;
import com.rabbitmq.client.CancelCallback;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;

/**
 * @program: rabbitmq-hello
 * @description: 一号线程 相当于之前讲的消费者
 * @author: Mr.dai
 * @create: 2021-09-10 10:33
 **/

public class Woker02 {
    //队列名称
    public static  final String QUEUE_NAME="hello";
    //接收消息
    public static void main(String[] args) throws Exception {
        Channel channel = RabbitMqUtils.getChannel();
        //消息的接收
        System.out.println("c2等待接收消息");
        DeliverCallback deliverCallback=( consumerTag,  message)->{
            System.out.println("worker02"+new String(message.getBody()));
        };
        //消息接收被取消时
        CancelCallback cancelCallback=(consumerTag)->{
            System.out.println(consumerTag+"worker02消费者取消");
        };
        //消息的接收
        channel.basicConsume(QUEUE_NAME,true,deliverCallback,cancelCallback);
    }

}
